<template>
  <div class="businessList">
    <a-card :bordered="false" style="width: 100%">
      <div slot="title">
        <a-icon type="left" class="mr10" @click="$router.go(-1)" />
        <span> 如果科技总/审批流管理/配置审批流 </span>
      </div>
      <p><a-button type="primary" @click="addNewCheckFlow">新增</a-button></p>
      <a-table
        :columns="workFlowListColumn"
        :data-source="dataSource"
        :scroll="{ x: 1000 }"
        :rowKey="(record) => record.id"
      >
        <div slot="opt" slot-scope="text, record">
          <a-space>
            <a-button type="primary" @click="update(record)" ghost
              >编辑</a-button
            >
            <a-button type="primary" @click="preview(record)" ghost
              >查看</a-button
            >
            <a-popconfirm @confirm="removeById(record)">
              <template slot="title">
                <p>确认删除?</p>
              </template>
              <a-button type="primary" ghost>删除</a-button>
            </a-popconfirm>
          </a-space>
        </div>
      </a-table>
    </a-card>
  </div>
</template>

<script>
import { CODE_SUCCESS } from "@/utils/consts";
import {getApi, postApi} from "@/services/autoApi";

const workFlowListColumn = [
  {
    title: "审批流名称",
    dataIndex: "approveConfigName"
  },
  {
    title: "审批ID",
    dataIndex: "id"
  },
  {
    title: "审批流上下线状态（状态)",
    dataIndex: "approveState",
    customRender: (val) => {
      if (val === 1) {
        return "启用";
      }
      return "停用";
    }
  },
  {
    title: "审批流创建时间",
    dataIndex: "createdTime"
  },
  {
    title: "审批流创建人",
    dataIndex: "createBy"
  },
  {
    title: "操作",
    dataIndex: "opt",
    scopedSlots: { customRender: "opt" }
  }
];
export default {
  name: "businessList",
  data() {
    return {
      workFlowListColumn,
      dataSource: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取列表
    getList() {
      const { businessFlowSubId } = this.$route.query;
      getApi("/approve/queryApproveConfig", { businessFlowSubId }).then(
        (res) => {
          const { code, message, data } = res.data;
          if (code === CODE_SUCCESS) {
            this.dataSource = data.approveConfigs;
            return;
          }
          this.$message.error(message);
        }
      );
    },
    addNewCheckFlow() {
      const { businessFlowSubId, businessFlowId } = this.$route.query;
      const actionType = "add";
      this.$router.push({
        path: "/system/flow",
        query: { businessFlowSubId, businessFlowId, actionType }
      });
    },
    preview(record) {
      const { id } = record;
      this.$router.push({
        path: "/system/flow",
        query: { id, actionType: "preview" }
      });
    },
    update(record) {
      const { id } = record;
      const { businessFlowSubId, businessFlowId } = this.$route.query;
      this.$router.push({
        path: "/system/flow",
        query: {
          actionType: "update",
          businessFlowSubId,
          businessFlowId,
          id
        }
      });
    },
    // 删除
    removeById(record) {
      const { id } = record;
      postApi("/approve/deleteById", { id }).then((res) => {
        const { code, message } = res.data;
        if (code !== CODE_SUCCESS) {
          this.$message.error(message);
          return;
        }
        this.$message.success(message);
        this.getList();
      });
    }
  }
};
</script>
